// packageC/pages/package/gonzhuangronqiguanli/5S_manage/5S_handling/handling.js
const mybehavior = require("../../../../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    baseUrl: "https://logisticsengineering.gree.com/self_form_backend/form_celery_manage",
    page: 1,
    page_size: 5,
    list: [],
  }, 
  // 点击任务详情跳转
  detailShow(e) {
    wx.requestSubscribeMessage({
      tmplIds: ['Qq4EMCt24ZVzeR74sHCcdCgZyo7pus8Bf9knNoUHPpM'],

    })
    console.log(e.currentTarget.dataset.row);
    let data = e.currentTarget.dataset.row
    wx.navigateTo({
      url: '/packageC/pages/package/gonzhuangronqiguanli/nanjin_manager/nanjing_handling/handling',
      success(res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', data)

      }
    })


  },
  getDaysBetweenDates(date1, date2) {
    // 将日期字符串转换为时间戳
    var t1 = new Date(date1).getTime();
    var t2 = new Date(date2).getTime();
    let differenceInMillis = t2 - t1;
    // 毫秒差值
    // 秒差值
    let differenceInSeconds = Math.floor(differenceInMillis / 1000);
    // 分钟差值
    let differenceInMinutes = Math.floor(differenceInSeconds / 60);
    // 小时差值
    let differenceInHours = Math.floor(differenceInMinutes / 60);
    // console.log(differenceInHours);
    // 天差值
    let differenceInDays = Math.floor(differenceInHours / 24);
    return (differenceInHours / 24).toFixed(1)
    // 计算两个时间戳之间的天数

  },
  // 获取待办数据
  getHandlingData() {
    let now_time = this.formatNowTime()
    let url = this.data.baseUrl + "/query_current_task"

    let data = {
      page: this.data.page,
      page_size: this.data.page_size,

    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
       console.log(res);
       let arr = res.data.results
       for (let i = 0; i < arr.length; i++) {
        arr[i].start_time =this.GMTToStr(arr[i].start_time) ;
         
       }
        // console.log(arr);
        this.setData({
          list: arr
        })
        wx.hideLoading()
      } else {
        wx.hideLoading()
        this.setData({
          list: [],
        })
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      wx.hideLoading()
      this.setData({
        list: [],
      })
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getHandlingData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    wx.showLoading({
      title: '获取数据中',
    })
    this.setData({
      page_size: this.data.page_size + 5
    })

    this.getHandlingData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})